$(function(){
//	获取url传值
	if(mid !==""){
		$('.solution').show();
	}
	function getQueryString(name) {
		var result = window.location.search.match(new RegExp("[\?\&]" + name + "=([^\&]+)", "i"));
		if (result == null || result.length < 1) {return "";}
			return result[1];
		}
		tid = getQueryString("id");
	$.ajax({
		type:"get",
		url:serverIP+"/user/mainTask/list",
		xhrFields:{
	        withCredentials: true    // 设置sessionId相同
	    },
	    async:false,
		success:function(data){
			let result = data.data.list.result;
			var strVar = "";
            result.map(function(u){
            	if(u.status=="01"){
            		window.location.href="Ptask.html?id="+tid;
            	}
            	if(u.taskId==tid){
	            	if(u.status == "01"){
	                    var status="未开始维护";
	                }else if(u.status == "02"){
	                    var status="正在维护中";
	                }else if(u.status == "03"){
	                    var status="维护完成";
	                }
	                if(u.grade == "01"){
	                	var grade="一级";
	                }else if(u.grade == "02"){
	                	var grade="二级";
	                }else if(u.grade == "03"){
	                	var grade="三级";
	                }
	            	strVar += "              <tr>";
				    strVar += "                <td>"+u.taskId+"<\/td>\n";
				    strVar += "                <td>"+u.taskExplain+"<\/td>\n";
				    strVar += "                <td>"+u.cName+"<\/td>\n";
				    strVar += "                <td>"+u.beginTime+"<\/td>\n";
				    strVar += "                <td>"+u.createTime+"<\/td>\n";
				    strVar += "                <td>"+status+"<\/td>\n";
				    strVar += "                <td>"+grade+"<\/td>\n";
				    strVar += "                <td>"+u.mName+"<\/td>\n";
				    strVar += "                <td>"+u.solution+"<\/td>\n";
				    strVar += "                <td>"+u.remark+"<\/td>\n";
				    strVar += "              <\/tr>";
				    return strVar;
				}
			})				
            $(".print-tbody").html(strVar);
        }
	});
    //	故障详情
	$.ajax({
		type:"get",
		url:serverIP+"/user/mainTask/view",
		xhrFields:{
	        withCredentials: true    // 设置sessionId相同
	    },
	    data:{taskId:tid},
		success:function(data){
			let result = data.data.list.result;
			var strVar = "";
            result.map(function(u){
                if(u.urgent == "01"){
                	var urgent="一级";
                }else if(u.urgent == "02"){
                	var urgent="二级";
                }else if(u.urgent == "03"){
                	var urgent="三级";
                }
                var ifMaint=u.ifMaint==true?"已维修":"未维修";
            	strVar += "              <tr>";
			    strVar += "                <td>"+u.codeName,+"<\/td>\n";
			    strVar += "                <td>"+u.origInfo+"<\/td>\n";
			    strVar += "                <td>"+urgent+"<\/td>\n";
			    strVar += "                <td>"+ifMaint+"<\/td>\n";
			    strVar += "              <\/tr>";
			    return strVar;
			})				
            $(".task-tbody").append(strVar);
        }
	});    
});
$('#selectOk').click(function(){
	var solution=$('#solution').val();
	var remark=$('#remark').val();
	if(solution !==""){
		$.ajax({ 
			type:"post",
			url:serverIP+"/user/mainTask/save",
			xhrFields:{
		        withCredentials: true    // 设置sessionId相同
		    },
			data: {taskId:tid,solution:solution,remark:remark},
			success:function(data){
				
			}
		})
	}else{
		alert("请填写解决方案");
		$('#solution').focus();;
	}
})
